package com.chat.transmission.event.source;

import com.chat.common.dto.MessageDTO;
import io.netty.channel.ChannelHandlerContext;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.net.InetSocketAddress;
import java.util.Objects;

/**
 * @author wei kunJie
 * @date 2024/3/23 16:57:10
 * 用户心跳后排队获取消息
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SendMsgEventSource {
    public InetSocketAddress userInetSocketAddress;
    public MessageDTO messageDTO;
    public ChannelHandlerContext ctx;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SendMsgEventSource that = (SendMsgEventSource) o;
        return Objects.equals(messageDTO.getId(), that.messageDTO.getId())
                && Objects.equals(userInetSocketAddress.getAddress(), that.userInetSocketAddress.getAddress())
                && Objects.equals(userInetSocketAddress.getHostString(), that.userInetSocketAddress.getHostString())
                && Objects.equals(userInetSocketAddress.getPort(), that.userInetSocketAddress.getPort())
                && Objects.equals(userInetSocketAddress.getHostName(), that.userInetSocketAddress.getHostName());
    }

    @Override
    public int hashCode() {
        return Objects.hash(
                messageDTO.getId(),
                userInetSocketAddress.getAddress(),
                userInetSocketAddress.getHostString(),
                userInetSocketAddress.getPort(),
                userInetSocketAddress.getHostName()
        );
    }
}
